package nc.ui.so.m32.billui.action;

import java.awt.event.ActionEvent;
import java.io.File;

import nc.bs.framework.common.NCLocator;
import nc.itf.so.m32.ISaleManageExtkkServer;
import nc.pub.so.m32.util.FileUtils;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.so.m32.billui.view.PdfPreviewUI;
import nc.ui.uif2.NCAction;
import nc.vo.so.m32.entity.SaleInvoiceVO;

public class FilePreviewAction extends NCAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private BillManageModel model;

	@Override
	public void doAction(ActionEvent e) throws Exception {
		SaleInvoiceVO billvo = (SaleInvoiceVO)getModel().getSelectedData();
		
		byte[] fbytes = NCLocator.getInstance().lookup(ISaleManageExtkkServer.class).saleInvoicePreviewFile(billvo);
		File file = FileUtils.byte2file(fbytes, "./PDF preview.pdf");
		
		PdfPreviewUI preview = new PdfPreviewUI(file);
		preview.setVisible(true);
	}

	public BillManageModel getModel() {
		return model;
	}

	public void setModel(BillManageModel model) {
		this.model = model;
		this.model.addAppEventListener(this);
	}

	@Override
	protected boolean isActionEnable() {
		SaleInvoiceVO selectedData = (SaleInvoiceVO)getModel().getSelectedData();
		if (selectedData!=null) {
			return true;
		} else {
			return false;
		}
		
	}
}
